package com.flowable.config;

import com.flowable.listener.DemoListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;

@Configuration
public class FlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    @Resource
    private DemoListener demoListener;

    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        // 关键：先获取事件监听器列表，若为null则初始化
        List<FlowableEventListener> eventListeners = engineConfiguration.getEventListeners();
        if (eventListeners == null) {
            eventListeners = new ArrayList<>();
            engineConfiguration.setEventListeners(eventListeners);
        }
        // 再添加自定义监听器
        eventListeners.add(demoListener);
    }
}